from django.db.models import Q
from rest_framework.views import APIView
from rest_framework.generics import ListAPIView,CreateAPIView
from recruit.serializers.detail_serializer import *
from rest_framework.response import Response


class ReSearchView(APIView):

    # queryset = Recruit.objects.all()


    def post(self,request):
        cityname = request.data.get('cityname')
        keyword = request.data.get('keyword')
        if keyword:
            recruit =  Recruit.objects.filter(Q(jobname__contains=keyword) & Q(city=cityname))
        else:
            recruit = Recruit.objects.filter(city=cityname)

        ser = RecruitSimpleSerializer(instance=recruit,many=True)

        return Response(ser.data)